from django.db import models


# Create your models here.
class Category(models.Model):
    title = models.CharField(verbose_name="分类", max_length=20, unique=True)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "分类"
        verbose_name_plural = "分类"


class Tag(models.Model):
    title = models.CharField(verbose_name="标签", max_length=20, unique=True)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "标签"
        verbose_name_plural = "标签"


class Book(models.Model):
    title = models.CharField(verbose_name="书名", max_length=20, unique=True)
    img = models.ImageField(verbose_name="图片", upload_to="image", blank=True, null=True)
    category = models.ForeignKey(verbose_name="所属分类", to=Category, on_delete=models.CASCADE)
    tag = models.ManyToManyField(verbose_name="内容标签", to=Tag, blank=True, null=True)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "小说"
        verbose_name_plural = "小说"
